/**
 * 排课管理
 */

<template>
  <div class="courseBox">
    <div class="courseBoxTop">
      <!-- 搜索 -->
      <div class="courseBoxTopSearch">
        <div class="courseName">
          <span>排课名称：</span>
          <el-input v-model="scheduleName" placeholder="请输入排课名称" />
        </div>
        <div class="profession">
          <span>学期：</span>
          <el-select v-model="semesterId" placeholder="请选择学期">
            <el-option
              v-for="item in schoolYearList"
              :key="item.id"
              :label="item.remarkSchool"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </div>
        <div class="version">
          <span>状态：</span>
          <el-select v-model="status" placeholder="请选择状态">
            <el-option label="启用" value="0"> </el-option>
            <el-option label="停用" value="1"> </el-option>
          </el-select>
        </div>

        <div class="searchAndReset">
          <el-button class="searchBtn" @click="searchInput">
            <i class="el-icon-search"></i>
            <span>搜索</span>
          </el-button>
          <el-button class="resetBtn" @click="refreshInput">
            <i class="el-icon-refresh"></i>
            <span>重置</span>
          </el-button>
        </div>
      </div>
    </div>

    <!-- 管理列表 -->
    <div class="courseBoxBottom">
      <div class="bottomHeader">
        <span class="title">管理列表</span>
        <div class="bottomHeaderBtn">
          <el-button class="addBtn" @click="openAddCourse">
            <i class="el-icon-plus"></i>
            <span>新增</span>
          </el-button>
          <el-button class="delBtn" @click="batchDelCourseScheduling">
            <i class="el-icon-close"></i>
            <span>批量删除</span>
          </el-button>
          <el-button class="toLeadBtn" @click.stop="setIsMaskOpen">
            <span class="icon iconfont icon-daoru"></span>
            <span>批量导入</span>

            <!-- 弹框 -->
            <div
              class="toLeadBtnMask"
              v-if="isMask"
              @mouseenter="setIsMaskOpen"
              @mouseleave="setIsMaskClose"
            >
              <span class="sanjiao"></span>
              <div class="ul">
                <el-upload
                  class="upload-demo"
                  action="https://jsonplaceholder.typicode.com/posts/"
                  :on-preview="handlePreview"
                >
                  <div class="li">
                    <i></i>
                    <el-button size="small" type="primary" class="importCourse">
                      导入排课数据
                    </el-button>
                  </div>
                </el-upload>

                <div class="li">
                  <i></i>
                  <span>下载导入模板</span>
                </div>
              </div>
            </div>
          </el-button>

          <el-button class="exportBtn" @click="exportCourseScheduling">
            <span class="icon iconfont icon-daochu"></span>
            <span>导出数据</span>
          </el-button>
        </div>
      </div>

      <!-- 表格 -->
      <div class="bottomMian">
        <el-table
          ref="multipleTable"
          :data="courseSchedulingList"
          tooltip-effect="dark"
          style="width: 100%"
          v-loading="isLoading"
          element-loading-text="加载中，请稍后..."
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="50"></el-table-column>
          <el-table-column
            type="index"
            label="序号"
            width="50"
          ></el-table-column>
          <el-table-column
            prop="scheduleName"
            label="排课名称"
            min-width="100"
          ></el-table-column>
          <el-table-column prop="gradeTypeName" label="年级"></el-table-column>
          <el-table-column prop="schoolYearName" label="学年学期" width="180">
            <template slot-scope="scope">
              {{ scope.row.schoolYearName }}
            </template>
          </el-table-column>
          <el-table-column prop="colleageName" label="学院"></el-table-column>
          <el-table-column
            prop="majorName"
            label="所属专业"
            min-width="120"
          ></el-table-column>
          <el-table-column
            prop="className"
            label="班级"
            min-width="115"
          ></el-table-column>
          <el-table-column
            prop="limitTime"
            label="截止时间"
            min-width="120"
          ></el-table-column>
          <el-table-column prop="courseScheduling" label="排课" min-width="80">
            <template slot-scope="scope">
              <span
                class="courseScheduling"
                @click="courseScheduling(scope.row)"
              >
                排课
              </span>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="发布状态">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.status"
                active-color="#13ce66"
                inactive-color="#C2C2C2"
                @change="updateStatus(scope.row)"
              >
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column prop="action" label="操作" width="160">
            <template slot-scope="scope">
              <div class="action">
                <span
                  class="icon"
                  @click="editCourseScheduling(scope.row)"
                >编辑</span>
                <span
                  class="icon"
                  @click="delCourseScheduling(scope.row.scheduleId)"
                >删除</span>

                <span class="copy" @click="copyCourse(scope.row)">复制</span>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!-- 分页 -->
      <div class="pagination" v-if="courseSchedulingList.length > 0">
        <el-pagination
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="10"
          prev-text="上一页"
          next-text="下一页"
          layout=" prev, pager, next"
          :total="total"
        >
        </el-pagination>
        <div class="jumper">
          跳到第
          <input type="text" ref="currentPage" value="1" />
          页
        </div>
        <button class="submit" @click="goPage">确定</button>
      </div>
    </div>

    <!-- 新增排课 -->
    <div class="dialog">
      <el-dialog
        :title="isEdit ? '编辑排课' : '添加排课'"
        :visible.sync="dialogFormVisible"
        center
        @close="closeAddCourse"
      >
        <el-form :model="form">
          <el-form-item label="排课名称:" :label-width="formLabelWidth">
            <el-input
              v-model="form.scheduleName"
              autocomplete="off"
              placeholder="请输入排课名称"
              style="width: 280px"
            ></el-input>
          </el-form-item>
          <el-form-item label="所属学院:" :label-width="formLabelWidth">
            <el-select
              v-model="form.colleageId"
              placeholder="请选择所属学院"
              style="width: 280px"
              clearable
              @clear="infoHandleClear"
              ref="infoSelectUpResId"
            >
              <!-- // 设置一个隐藏的下拉选项
              // 如果不设置一个下拉选项，下面的树形组件将无法正常使用 -->
              <el-option hidden :value="form.colleageId" :label="colleageName">
              </el-option>
              <!-- // 设置树形组件
                是否在点击节点的时候展开或者收缩节点， 默认值为 true，如果为 false，则只有点箭头图标的时候才会展开或者收缩节点。
                // 是否在点击节点的时候选中节点，默认值为 false，即只有在点击复选框时才会选中节点。
                  // 节点被点击时的回调 -->
              <el-tree
                :data="editSeletOptions"
                :props="defaultProps"
                :expand-on-click-node="false"
                :check-on-click-node="true"
                @node-click="infoHandleNodeClick"
              >
              </el-tree>
            </el-select>
          </el-form-item>

          <el-form-item label="所属专业:" :label-width="formLabelWidth">
            <el-select
              v-model="form.majorId"
              placeholder="请选择所属专业"
              style="width: 280px"
              @change="getClassList"
            >
              <el-option
                v-for="(item, index) in majorList"
                :key="index"
                :label="item.majorName"
                :value="item.majorId"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="年级:" :label-width="formLabelWidth">
            <el-select
              v-model="form.gradeTypeId"
              placeholder="请选择年级"
              style="width: 280px"
            >
              <el-option
                v-for="item in gradeOptions"
                :key="item.typeId"
                :label="item.typeName"
                :value="item.typeId"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="所属班级:" :label-width="formLabelWidth">
            <el-select
              v-model="form.classId"
              placeholder="请选择所属班级"
              style="width: 280px"
            >
              <el-option
                v-for="item in classListData"
                :key="item.classId"
                :label="item.className"
                :value="item.classId"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="学年学期:" :label-width="formLabelWidth">
            <el-select
              v-model="form.semesterId"
              placeholder="请选择学年学期"
              style="width: 280px"
            >
              <el-option
                v-for="item in schoolYearList"
                :key="item.id"
                :label="item.remarkSchool"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="计划课时:" :label-width="formLabelWidth">
            <el-input
              v-model="form.totalLessonPeriod"
              autocomplete="off"
              placeholder="请输入计划课时"
              style="width: 280px"
            ></el-input>
          </el-form-item>

          <el-form-item label="周课时:" :label-width="formLabelWidth">
            <el-input
              v-model="form.weekLessonPeriod"
              autocomplete="off"
              placeholder="请输入周课时"
              style="width: 280px"
            ></el-input>
          </el-form-item>

          <el-form-item label="周次:" :label-width="formLabelWidth">
            <el-input
              v-model="form.weeks"
              autocomplete="off"
              placeholder="请输入周次"
              style="width: 280px"
            ></el-input>
          </el-form-item>

          <el-form-item label="截止时间:" :label-width="formLabelWidth">
            <div class="block">
              <el-date-picker
                v-model="form.limitTime"
                align="center"
                type="date"
                placeholder="请选择时间"
              >
              </el-date-picker>
            </div>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="closeAddCourse">取 消</el-button>
          <el-button type="primary" @click="confirmAddCourse">确 定</el-button>
        </div>
      </el-dialog>
    </div>

    <!-- 排课 -->
    <div class="dialog1">
      <el-dialog
        title="排课"
        :visible.sync="dialogVisible"
        center
        @close="closeDialogVisible"
        v-loading.lock="isLoading"
      >
        <div class="dialogBox">
          <div class="header">
            {{ courseObj.scheduleName }}
            {{ courseObj.gradeTypeName }}
            {{ courseObj.schoolYearName }}
            {{ courseObj.colleageName }}
            {{ courseObj.majorName }}
            {{ courseObj.className }}
          </div>
          <table class="mian" border="1" cellspacing="0" cellpadding="0">
            <thead class="thd">
              <tr v-for="(item, index) in weekList" :key="index" class="thd_tr">
                <th class="thd_th" :style="index === 1 ? 'width:200px' : ''">
                  {{ item.title }}
                </th>
              </tr>
            </thead>
            <tbody class="tbd" @mousedown="setItemColor">
              <tr v-for="(item, index) in hourList" :key="index" class="tbd_tr">
                <td class="tbd_td tbd_title">
                  {{ item.title }}
                </td>
                <td class="time tbd_td" style="width: 200px">
                  <el-time-picker
                    v-model="item.timeSlots"
                    is-range
                    prefix-icon="false"
                    range-separator="-"
                    format="HH:mm"
                  >
                  </el-time-picker>
                </td>
                <td
                  v-for="(it, ind) in item.children"
                  :key="ind"
                  :class="it.calssName ? it.calssName + ' tbd_td' : 'tbd_td'"
                  :data-id="item.id + '-' + it.id"
                >
                  <template>{{ it.title }}</template>
                </td>
              </tr>
            </tbody>
          </table>
          <div slot="footer" class="dialog-footer">
            <el-button class="close" @click="closeDialogVisible"
              >取 消</el-button
            >
            <el-button type="primary" @click="submitCourse">保 存</el-button>
          </div>
        </div>

        <!-- 颜色弹框 -->
        <div class="colorBox" v-show="colorFlag" ref="colorBox">
          <div class="colorBoxTop">
            <div class="colorBoxColor">
              <h4>选择颜色</h4>
              <ul class="colorBoxUl">
                <li class="colorBoxLi" @click="(e) => setColor(e, '')">
                  <i class="white"></i>
                  <span>默认</span>
                  <b class="yes">√</b>
                </li>
                <li class="colorBoxLi" @click="(e) => setColor(e, 'green')">
                  <i class="green"></i>
                  <span>可排课</span>
                  <b class="yes">√</b>
                </li>
                <li class="colorBoxLi" @click="(e) => setColor(e, 'blue')">
                  <i class="blue"></i>
                  <span>阶段排课</span>
                  <b class="yes">√</b>
                </li>
                <li class="colorBoxLi" @click="(e) => setColor(e, 'yellow')">
                  <i class="yellow"></i>
                  <span>必修课</span>
                  <b class="yes">√</b>
                </li>
                <li class="colorBoxLi" @click="(e) => setColor(e, 'red')">
                  <i class="red"></i>
                  <span>已排课</span>
                  <b class="yes">√</b>
                </li>
                <li class="colorBoxLi" @click="(e) => setColor(e, 'gray')">
                  <i class="disabled"></i>
                  <span>不排课</span>
                  <b class="yes">√</b>
                </li>
              </ul>
            </div>

            <div class="colorBoxSelect">
              <div class="selectCourse">
                <h4>选择课程</h4>
                <el-select
                  v-model="selectCourse"
                  filterable
                  placeholder="请选择"
                  style="width: 150px"
                >
                  <el-option
                    v-for="item in courseList"
                    :key="item.courseId"
                    :label="item.courseName"
                    :value="item.courseId + ' ' + item.courseName"
                  >
                  </el-option>
                </el-select>
              </div>

              <div class="selectTeacher" v-permission="['admin', 'editor']">
                <h4>选择教师</h4>
                <el-select
                  v-model="selectTeacher"
                  filterable
                  placeholder="请选择"
                  style="width: 150px"
                >
                  <el-option
                    v-for="item in teacherList"
                    :key="item.id"
                    :label="item.teacherName"
                    :value="item.teacherName"
                  >
                  </el-option>
                </el-select>
              </div>
            </div>
          </div>

          <div class="colorBoxBtn">
            <el-button class="close" @click="closeSelect">取 消</el-button>
            <el-button type="primary" class="submit" @click="setCourseColor"
              >确 定</el-button
            >
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import "@/styles/picture.scss";
import {
  exportApi,
  getMajorListApi,
  addCourseListApi,
  delCourseSchedulingApi,
  getCourseListDetailApi,
  getCourseSchedulingListApi,
  addCourseSchedulingListApi,
  editCourseSchedulingListApi,
} from "@/api/educational/courseScheduling";

import {
  getGradeListApi,
  schoolYearItemApi,
  colleageTreeDataApi,
  getClassGradeListApi,
} from "@/api/basics/teachingPlan";
// import {
// getSchoolYearApi
// } from "@/api/basics/teachingPlan"
import { getCourseListApi } from "@/api/basics/course";
import { getTeacherListDataApi } from "@/api/educational/teacherManagement";
import moment from "moment";
import { _debounce } from "@/utils/debounce";
export default {
  data() {
    return {
      isEdit: false,
      total: 0,
      teacherList: [],
      courseSchedulingList: [],
      id: "",
      courseId: "",
      color: "",
      selectCourse: "",
      selectTeacher: "",
      semesterId: "",
      status: "",
      scheduleName: "",
      multipleSelection: [],
      currentPage: 1,
      pageSize: 10,
      isMask: false,
      isLoading: false,
      colorFlag: false,
      dialogFormVisible: false,
      dialogVisible: false,
      form: {
        scheduleId: "",
        scheduleName: "",
        colleageId: "",
        majorId: "",
        gradeTypeId: "",
        classId: "",
        semesterId: "",
        totalLessonPeriod: "",
        weekLessonPeriod: "",
        weeks: "",
        limitTime: "",
      },
      formLabelWidth: "100px",
      courseSchedulingData: {},
      courseObj: {},
      hourList: [
        {
          id: "1",
          title: "早1",
          rowNum: 1,
          timeSlots: "",
          children: [
            {
              id: 0,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 1,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 2,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 3,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 4,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 5,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 6,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
          ],
        },
        {
          id: "2",
          title: "第一节",
          rowNum: 2,
          timeSlots: "",
          children: [
            {
              id: 0,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 1,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 2,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 3,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 4,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 5,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 6,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
          ],
        },
        {
          id: "3",
          title: "第二节",
          rowNum: 3,
          timeSlots: "",
          children: [
            {
              id: 0,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 1,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 2,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 3,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 4,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 5,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 6,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
          ],
        },
        {
          id: "13",
          title: "课间",
          rowNum: 4,
          timeSlots: "",
          children: [
            {
              id: 0,
              title: "",
              calssName: "disabled",
              courseId: "",
              courseName: "",

              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 1,
              title: "",
              calssName: "disabled",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 2,
              title: "",
              calssName: "disabled",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 3,
              title: "",
              calssName: "disabled",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 4,
              title: "",
              calssName: "disabled",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 5,
              title: "",
              calssName: "disabled",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 6,
              title: "",
              calssName: "disabled",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
          ],
        },
        {
          id: "4",
          title: "第三节",
          rowNum: 4,
          timeSlots: "",
          children: [
            {
              id: 0,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 1,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 2,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 3,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 4,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 5,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 6,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
          ],
        },
        {
          id: "5",
          title: "第四节",
          rowNum: 5,
          timeSlots: "",
          children: [
            {
              id: 0,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 1,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 2,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 3,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 4,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 5,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 6,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
          ],
        },
        {
          id: "14",
          title: "午休",
          rowNum: 5,
          timeSlots: "",
          children: [
            {
              id: 0,
              title: "",
              calssName: "disabled",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 1,
              title: "",
              calssName: "disabled",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 2,
              title: "",
              calssName: "disabled",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 3,
              title: "",
              calssName: "disabled",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 4,
              title: "",
              calssName: "disabled",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 5,
              title: "",
              calssName: "disabled",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 6,
              title: "",
              calssName: "disabled",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
          ],
        },
        {
          id: "6",
          title: "第五节",
          rowNum: 6,
          timeSlots: "",
          children: [
            {
              id: 0,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 1,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 2,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 3,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 4,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 5,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 6,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
          ],
        },
        {
          id: "7",
          title: "第六节",
          rowNum: 7,
          timeSlots: "",
          children: [
            {
              id: 0,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 1,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 2,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 3,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 4,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 5,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 6,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
          ],
        },
        {
          id: "8",
          title: "第七节",
          rowNum: 8,
          timeSlots: "",
          children: [
            {
              id: 0,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 1,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 2,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 3,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 4,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 5,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 6,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
          ],
        },
        {
          id: "9",
          title: "第八节",
          rowNum: 9,
          timeSlots: "",
          children: [
            {
              id: 0,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 1,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 2,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 3,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 4,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 5,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 6,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
          ],
        },
        {
          id: "11",
          title: "晚1",
          rowNum: 11,
          timeSlots: "",
          children: [
            {
              id: 0,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 1,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 2,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 3,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 4,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 5,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 6,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
          ],
        },
        {
          id: "12",
          title: "晚2",
          rowNum: 12,
          timeSlots: "",
          children: [
            {
              id: 0,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 1,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 2,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 3,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 4,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 5,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
            {
              id: 6,
              title: "",
              calssName: "",
              courseId: "",
              courseName: "",
              teacherId: "",
              teacherName: "",
              courseSchedulingId: "",
            },
          ],
        },
      ],
      weekList: [
        {
          title: "",
        },
        {
          title: "时间",
        },
        {
          title: "星期一",
        },
        {
          title: "星期二",
        },
        {
          title: "星期三",
        },
        {
          title: "星期四",
        },
        {
          title: "星期五",
        },
        {
          title: "星期六",
        },
        {
          title: "星期日",
        },
      ],
      hourList1: [],
      filename: "排课管理",
      defaultProps: {
        children: "children",
        label: "label",
      },
      colleageName: "",
      majorList: [],
      courseList: [],
      gradeOptions: [],
      classListData: [],
      schoolYearList: [],
      editSeletOptions: [],
      params: {
        beginTime: moment(new Date()).format("YYYY-MM-DD"),
        endTime: moment(
          new Date().setFullYear(new Date().getFullYear() + 5)
        ).format("YYYY-MM-DD"),
      },
    };
  },

  mounted() {
    this.hourList1 = [...this.hourList];

    // 获取排课列表
    this.getCourseSchedulingList({
      pageNum: this.currentPage,
      pageSize: this.pageSize,
    });

    // 获取学年学期
    this.getSchoolYear();

    // 获取课程列表
    this.getCourseList({ pageNum: this.currentPage, pageSize: this.pageSize });

    // 获取教师列表
    this.getTeacherListData();
  },

  methods: {
    // 新增所属学院下拉框
    async editSelectTreeData() {
      const res = await colleageTreeDataApi();
      if (res.code === 200) {
        this.editSeletOptions = res.data;
      }
    },

    // 年级列表
    async getGradeList() {
      const res = await getGradeListApi({ parentId: 55 });
      this.gradeOptions = res.rows;
    },

    // 获取所属专业列表
    async getMajorList(id) {
      if (id) {
        let res = await getMajorListApi({ colleageId: id, pageSize: 100 });
        if (res.code === 200) {
          this.majorList = res.data.filter((item) => {
            return item.status == "0";
          });
        }
      } else {
        let res = await getMajorListApi();
        if (res.code === 200) {
          this.majorList = res.data.filter((item) => {
            return item.status == "0";
          });
        }
      }
    },

    // 获取学年学期
    async getSchoolYear() {
      const res = await schoolYearItemApi();
      if (res.code === 200) {
        this.schoolYearList = res.data;
      }
    },

    // 获取班级列表
    async getClassGradeList(id) {
      if (id) {
        await getClassGradeListApi({ majorId: id, pageSize: 100 }).then(
          (res) => {
            this.classListData = res.rows.filter((item) => {
              return item.status == "0";
            });
          }
        );
      } else {
        await getClassGradeListApi().then((res) => {
          this.classListData = res.rows.filter((item) => {
            return item.status == "0";
          });
        });
      }
    },

    // 选择专业 请求班级列表
    getClassList(val) {
      this.getClassGradeList(val);
    },

    // 获取教师列表
    async getTeacherListData() {
      const res = await getTeacherListDataApi();
      this.teacherList = res.rows;
    },

    //  获取课程列表 / 搜索
    async getCourseList(data) {
      let result = await getCourseListApi(data);
      if (result.code === 200) {
        this.courseList = result.rows;
      }
    },

    // 将选择器的值置空
    infoHandleClear() {
      this.colleageName = "";
      this.form.colleageId = "";
    },

    // 弹框下拉树
    infoHandleNodeClick(data) {
      // // 这里主要配置树形组件点击节点后，设置选择器的值；自己配置的数据，仅供参考
      this.colleageName = data.label;
      this.form.colleageId = data.id;
      this.getMajorList(data.id);
      // // 选择器执行完成后，使其失去焦点隐藏下拉框的效果
      this.$refs.infoSelectUpResId.blur();
    },

    // 获取排课列表
    async getCourseSchedulingList(data) {
      await getCourseSchedulingListApi({ ...data, params: this.params }).then(
        (res) => {
          if (res.code === 200) {
            this.total = res.total;
            this.courseSchedulingList = res.rows.map((item) => {
              return {
                ...item,
                status: item.status == "0" ? true : false,
              };
            });
          }
        }
      );
    },

    // 开启排课弹框
    courseScheduling(val) {
      this.courseObj = val;
      this.courseId = val.scheduleId;
      this.isLoading = true;
      getCourseListDetailApi({ scheduleId: val.scheduleId }).then((res) => {
        if (res.code === 200) {
          this.isLoading = false;

          if (res.data.children.length > 0) {
            let arr = res.data.children.splice(0, 3);
            arr.push({
              id: "13", // id
              title: "课间", // 一级标题
              rowNum: 4, // 排序 标识
              timeSlots: "",
              children: [
                {
                  id: "13-1", // id
                  title: "", // 标题
                  calssName: "disabled", // 类名
                  courseId: "", // 课程id
                  courseName: "", // 课程名称
                  courseSchedulingId: "", // 排课id
                },
                {
                  id: "13-2", // id
                  title: "", // 标题
                  calssName: "disabled", // 类名
                  courseId: "", // 课程id
                  courseName: "", // 课程名称
                  courseSchedulingId: "", // 排课id
                },
                {
                  id: "13-3", // id
                  title: "", // 标题
                  calssName: "disabled", // 类名
                  courseId: "", // 课程id
                  courseName: "", // 课程名称
                  courseSchedulingId: "", // 排课id
                },
                {
                  id: "13-4", // id
                  title: "", // 标题
                  calssName: "disabled", // 类名
                  courseId: "", // 课程id
                  courseName: "", // 课程名称
                  courseSchedulingId: "", // 排课id
                },
                {
                  id: "13-5", // id
                  title: "", // 标题
                  calssName: "disabled", // 类名
                  courseId: "", // 课程id
                  courseName: "", // 课程名称
                  courseSchedulingId: "", // 排课id
                },
                {
                  id: "13-6", // id
                  title: "", // 标题
                  calssName: "disabled", // 类名
                  courseId: "", // 课程id
                  courseName: "", // 课程名称
                  courseSchedulingId: "", // 排课id
                },
                {
                  id: "13-7", // id
                  title: "", // 标题
                  calssName: "disabled", // 类名
                  courseId: "", // 课程id
                  courseName: "", // 课程名称
                  courseSchedulingId: "", // 排课id
                },
              ],
            });

            let arr1 = res.data.children.splice(0, 2);
            arr1.push({
              id: "14", // id
              title: "午休", // 一级标题
              rowNum: 7, // 排序 标识
              timeSlots: "",
              children: [
                {
                  id: "14-1", // id
                  title: "", // 标题
                  calssName: "disabled", // 类名
                  courseId: "", // 课程id
                  courseName: "", // 课程名称
                  courseSchedulingId: "", // 排课id
                },
                {
                  id: "14-2", // id
                  title: "", // 标题
                  calssName: "disabled", // 类名
                  courseId: "", // 课程id
                  courseName: "", // 课程名称
                  courseSchedulingId: "", // 排课id
                },
                {
                  id: "14-3", // id
                  title: "", // 标题
                  calssName: "disabled", // 类名
                  courseId: "", // 课程id
                  courseName: "", // 课程名称
                  courseSchedulingId: "", // 排课id
                },
                {
                  id: "14-4", // id
                  title: "", // 标题
                  calssName: "disabled", // 类名
                  courseId: "", // 课程id
                  courseName: "", // 课程名称
                  courseSchedulingId: "", // 排课id
                },
                {
                  id: "14-5", // id
                  title: "", // 标题
                  calssName: "disabled", // 类名
                  courseId: "", // 课程id
                  courseName: "", // 课程名称
                  courseSchedulingId: "", // 排课id
                },
                {
                  id: "14-6", // id
                  title: "", // 标题
                  calssName: "disabled", // 类名
                  courseId: "", // 课程id
                  courseName: "", // 课程名称
                  courseSchedulingId: "", // 排课id
                },
                {
                  id: "14-7", // id
                  title: "", // 标题
                  calssName: "disabled", // 类名
                  courseId: "", // 课程id
                  courseName: "", // 课程名称
                  courseSchedulingId: "", // 排课id
                },
              ],
            });
            let data = [...arr, ...arr1, ...res.data.children];
            data.forEach((item) => {
              let arr = item.timeSlots.split("-");
              if (item.timeSlots) {
                item.timeSlots = [
                  new Date(new Date().toJSON().split("T")[0] + " " + arr[0]),
                  new Date(new Date().toJSON().split("T")[0] + " " + arr[1]),
                ];
              } else {
                item.timeSlots = [];
              }
            });
            this.hourList = data;
          } else {
            this.hourList = [...this.hourList1];
          }
        }
      });

      let data = localStorage.getItem("data");
      if (data) {
        let { id, list } = JSON.parse(data);
        if (id == this.courseId) {
          this.hourList = list;
        } else {
          this.hourList = [...this.hourList1];
        }
      }
      this.colorFlag = false;
      this.dialogVisible = true;
    },

    // 关闭排课弹框
    closeDialogVisible() {
      this.colorFlag = false;
      this.dialogVisible = false;
      this.hourList = [...this.hourList1];
    },

    // 点击设置颜色框位置
    setItemColor(e) {
      if (
        // e.target.className != "tbd_td" &&
        e.target.className != "green tbd_td" &&
        e.target.className != "blue tbd_td" &&
        e.target.className != "yellow tbd_td" &&
        e.target.className != "red tbd_td" &&
        e.target.className != "gray tbd_td"
      ) {
        this.color = "";
        this.selectCourse = "";
        this.selectTeacher = "";
        // 获取对号元素列表
        let yesList = document.querySelectorAll(".yes");
        // 隐藏对号元素
        yesList.forEach((item) => {
          item.className = "yes none";
        });
      } else {
        let ind = 0;

        e.target.className == "tbd_td"
          ? (ind = 0)
          : e.target.className == "green tbd_td"
          ? (ind = 1)
          : e.target.className == "blue tbd_td"
          ? (ind = 2)
          : e.target.className == "yellow tbd_td"
          ? (ind = 3)
          : e.target.className == "red tbd_td"
          ? (ind = 4)
          : e.target.className == "gray tbd_td"
          ? (ind = 5)
          : (ind = 6);

        // 获取对号元素列表
        let yesList = document.querySelectorAll(".yes");
        // 隐藏对号元素
        yesList.forEach((item) => {
          item.className = "yes none";
        });

        // 设置当前选择的颜色  显示
        yesList[ind].className = "yes block";

        this.hourList.forEach((item) => {
          item.children.forEach((it) => {
            if (item.id + "-" + it.id == e.target.dataset.id) {
              this.color = it.calssName;
              this.selectTeacher = it.teacherName;
              this.selectCourse =
                it.courseId && it.courseName
                  ? it.courseId + " " + it.courseName
                  : "";
              this.hourList = [...this.hourList];
            }
          });
        });
      }
      if (
        e.target.className != "tbd_td tbd_title" &&
        e.target.className != "time tbd_td" &&
        e.target.className != "el-range-input" &&
        e.target.className != "el-range-separator" &&
        e.target.className != "el-input__icon el-range__icon false" &&
        e.target.className != "el-input__icon el-range__close-icon" &&
        e.target.className !=
          "el-input__icon el-range__close-icon el-icon-circle-close" &&
        e.target.className !=
          "el-date-editor el-range-editor el-input__inner el-date-editor--timerange" &&
        e.target.className !=
          "el-date-editor el-range-editor el-input__inner el-date-editor--timerange is-active" &&
        e.target.className != "disabled tbd_td"
      ) {
        this.id = e.target.dataset.id;
        this.colorFlag = true;
        let { layerX, layerY } = e;
        this.$refs.colorBox.style = `top:${layerY + 12}px;
        left:${layerX - 75}px;`;
      } else {
        this.colorFlag = false;
      }
    },

    // 点击色块改变每一格的颜色
    setColor(e, color) {
      this.color = color;
      // 获取对号元素列表
      let yesList = document.querySelectorAll(".yes");
      // 隐藏对号元素
      yesList.forEach((item) => {
        item.className = "yes none";
      });

      if (e.target.className == "colorBoxLi") {
        e.target.children[2].className = "yes block";
      } else {
        // 给当前元素设置类名  显示
        e.target.parentNode.children[2].className = "yes block";
      }
    },

    // 确定改变颜色
    setCourseColor() {
      this.hourList.forEach((item) => {
        item.children.forEach((it) => {
          let arr = this.id.split("-");
          if (item.id == arr[0] && it.id == arr[1]) {
            it.calssName = this.color;
            it.courseId = this.selectCourse.split(" ")[0];
            it.teacherName = this.selectTeacher;
            it.courseName =
              this.color == "gray" ? "" : this.selectCourse.split(" ")[1];
            it.title =
              this.color == "gray" ? "" : this.selectCourse.split(" ")[1];
            this.hourList = [...this.hourList];
          }
        });
      });
      console.log(this.hourList);
      this.colorFlag = false;

      let data = {
        id: this.courseId,
        list: this.hourList,
      };

      localStorage.setItem("data", JSON.stringify(data));
    },

    // 取消改变颜色
    closeSelect() {
      this.colorFlag = false;
    },

    //保存
    submitCourse: _debounce(function () {
      this.$message("保存中~");
      this.colorFlag = false;
      this.dialogVisible = false;
      this.hourList.splice(3, 1);
      this.hourList.splice(5, 1);
      this.courseObj.children = this.hourList;
      this.hourList.forEach((item) => {
        if (item.timeSlots.length > 0) {
          item.timeSlots =
            moment(item.timeSlots[0]).format("HH:mm") +
            "-" +
            moment(item.timeSlots[1]).format("HH:mm");
        }
      });
      addCourseListApi(this.courseObj).then((res) => {
        if (res.code === 200) {
          this.$message.success("保存成功！");
          localStorage.removeItem("data");

          this.hourList = [...this.hourList];
        } else {
          this.$message.error("保存失败！");
        }
      });
    }, 500),

    // 复制
    copyCourse(data) {
      this.$message("复制中~");
      console.log(data);
      // 新增排课
      addCourseSchedulingListApi({ ...data, status: "0", scheduleId: "" }).then(
        (res) => {
          if (res.code === 200) {
            this.$message.success("复制成功!");
            this.getCourseSchedulingList({
              pageNum: this.currentPage,
              pageSize: this.pageSize,
            }).then(() => {
              getCourseListDetailApi({ scheduleId: data.scheduleId }).then(
                (res) => {
                  if (res.data.children.length > 0) {
                    let data = {
                      ...res.data,
                      scheduleId: this.courseSchedulingList[0].scheduleId,
                    };
                    addCourseListApi(data);
                  }
                }
              );
            });
          } else {
            this.$message.error("复制失败!");
          }
        }
      );
    },

    // 搜索
    searchInput() {
      let data = {
        scheduleName: this.scheduleName,
        semesterId: this.semesterId,
        status: this.status,
      };

      this.getCourseSchedulingList({
        pageNum: this.currentPage,
        pageSize: this.pageSize,
        ...data,
      });
    },

    // 重置
    refreshInput() {
      this.scheduleName = "";
      this.semesterId = "";
      this.status = "";

      this.getCourseSchedulingList({
        pageNum: this.currentPage,
        pageSize: this.pageSize,
      });
    },

    // 新增排课
    openAddCourse() {
      this.isEdit = false;
      this.dialogFormVisible = true;
      this.form = {
        scheduleName: "",
        colleageId: "",
        majorId: "",
        gradeTypeId: "",
        classId: "",
        semesterId: "",
        totalLessonPeriod: "",
        weekLessonPeriod: "",
        weeks: "",
        limitTime: "",
      };
      this.colleageName = "";
      // 获取所属专业列表
      this.getMajorList();

      // 获取学年学期列表
      this.getSchoolYear();

      // 获取年级列表
      this.getGradeList();

      // 获取班级列表
      this.getClassGradeList();

      // 获取所属学院列表
      this.editSelectTreeData();
    },

    // 编辑排课
    editCourseScheduling(data) {
      // 获取所属专业列表
      this.getMajorList();

      // 获取学年学期列表
      this.getSchoolYear();

      // 获取年级列表
      this.getGradeList();

      // 获取班级列表
      this.getClassGradeList();

      // 获取所属学院列表
      this.editSelectTreeData();

      this.form = data;
      this.isEdit = true;
      this.isLoading = true;
      this.dialogFormVisible = true;

      this.colleageName = data.colleageName;
    },

    // 取消
    closeAddCourse() {
      this.dialogFormVisible = false;
      this.isLoading = false;
      this.form = {
        scheduleId: "",
        scheduleName: "",
        colleageId: "",
        majorId: "",
        gradeTypeId: "",
        classId: "",
        semesterId: "",
        totalLessonPeriod: "",
        weekLessonPeriod: "",
        weeks: "",
        limitTime: "",
      };
    },

    // 确定
    confirmAddCourse: _debounce(function () {
      let {
        scheduleName,
        colleageId,
        majorId,
        gradeTypeId,
        classId,
        semesterId,
        totalLessonPeriod,
        weekLessonPeriod,
        weeks,
        limitTime,
      } = this.form;

      this.form = {
        ...this.form,
        status: this.form.status ? "0" : "1",
        limitTime: moment(this.form.limitTime).format("YYYY-MM-DD"),
      };
      if (
        scheduleName &&
        colleageId &&
        majorId &&
        gradeTypeId &&
        classId &&
        semesterId &&
        totalLessonPeriod &&
        weekLessonPeriod &&
        weeks &&
        limitTime
      ) {
        if (this.isEdit) {
          this.$message("修改中，请稍候~");
          // 编辑排课
          editCourseSchedulingListApi(this.form).then((res) => {
            if (res.code === 200) {
              this.$message.success("修改成功!");
              this.getCourseSchedulingList({
                pageNum: this.currentPage,
                pageSize: this.pageSize,
              });
              this.isLoading = false;
              this.dialogFormVisible = false;
            } else {
              this.$message.error("修改失败!");
            }
          });
        } else {
          let data = { ...this.form, status: "0" };
          this.$message("添加中，请稍候~");
          // 新增排课
          addCourseSchedulingListApi(data).then((res) => {
            if (res.code === 200) {
              this.$message.success("添加成功!");
              this.getCourseSchedulingList({
                pageNum: this.currentPage,
                pageSize: this.pageSize,
              });
              this.dialogFormVisible = false;
            } else {
              this.$message.error("添加失败!");
            }
          });
        }
      } else if (!scheduleName) {
        this.$message.error("排课名称不能为空！");
      } else if (!colleageId) {
        this.$message.error("请选择所属学院！");
      } else if (!majorId) {
        this.$message.error("请选择所属专业！");
      } else if (!gradeTypeId) {
        this.$message.error("请选择年级！");
      } else if (!classId) {
        this.$message.error("请选择所属班级！");
      } else if (!semesterId) {
        this.$message.error("请选择学年学期！");
      } else if (!totalLessonPeriod) {
        this.$message.error("计划总课时不能为空！");
      } else if (!weekLessonPeriod) {
        this.$message.error("周课时不能为空");
      } else if (!weeks) {
        this.$message.error("周次不能为空");
      } else if (!limitTime) {
        this.$message.error("请选择创建时间！");
      }
    }, 1000),

    // 修改发布状态
    updateStatus(data) {
      let { scheduleId, status } = data;
      editCourseSchedulingListApi({
        scheduleId,
        status: status ? "0" : "1",
      }).then((res) => {
        if (res.code === 200) {
          this.$message.success("修改成功!");
          this.dialogFormVisible = false;
          this.getCourseSchedulingList({
            pageNum: this.currentPage,
            pageSize: this.pageSize,
          });
        } else {
          this.$message.error("修改失败!");
        }
      });
    },

    // 删除
    delCourseScheduling(ids) {
      this.$confirm("此操作将删除该排课, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          delCourseSchedulingApi({ ids }).then((res) => {
            if (res.code === 200) {
              this.$message.success("删除成功!");
              // 获取排课列表
              this.getCourseSchedulingList({
                pageNum: this.currentPage,
                pageSize: this.pageSize,
              });
            } else {
              this.$message.error("删除失败!");
            }
          });
        })
        .catch(() => {});
    },

    // 批量删除
    batchDelCourseScheduling() {
      if (this.multipleSelection.length) {
        let data = [...this.multipleSelection].map((item) => {
          return "" + item.scheduleId;
        });
        this.$confirm("此操作将删除已选择的排课, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            delCourseSchedulingApi({ ids: data.join(",") }).then((res) => {
              if (res.code === 200) {
                this.$message.success("删除成功!");
                // 获取排课列表
                this.getCourseSchedulingList({
                  pageNum: this.currentPage,
                  pageSize: this.pageSize,
                });
              } else {
                this.$message.error("删除失败!");
              }
            });
          })
          .catch(() => {});
      } else {
        this.$message.error("请选择要删除的课程！");
      }
    },

    // 导出排课
    exportCourseScheduling() {
      this.$confirm("是否导出全部数据？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          exportApi().then((res) => {
            if (!res) return;
            const blob = new Blob([res], {
              type: "application/vnd.ms-excel",
            }); // 构造一个blob对象来处理数据，并设置文件类型
            if (window.navigator.msSaveOrOpenBlob) {
              //兼容IE10
              navigator.msSaveBlob(blob, this.filename);
            } else {
              const href = URL.createObjectURL(blob); //创建新的URL表示指定的blob对象
              const a = document.createElement("a"); //创建a标签
              a.style.display = "none";
              a.href = href; // 指定下载链接
              a.download = this.filename; //指定下载文件名
              a.click(); //触发下载
              URL.revokeObjectURL(a.href); //释放URL对象
            }
          });
        })
        .catch(() => {});
    },

    // 打开导入弹框
    setIsMaskOpen() {
      this.isMask = true;
    },

    // 关闭导入弹框
    setIsMaskClose() {
      this.isMask = false;
    },

    // 导入上传
    handlePreview(file) {
      console.log(file);
    },

    // 已选中
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    // 设置当前页码
    handleCurrentChange(val) {
      this.currentPage = val;
      // 获取课程列表
      this.getCourseSchedulingList({
        pageNum: this.currentPage,
        pageSize: this.pageSize,
      });
    },

    // 跳转当前页
    goPage() {
      let { value } = this.$refs.currentPage;
      this.currentPage = Number(value);
      // 获取课程列表
      this.getCourseSchedulingList({
        pageNum: this.currentPage,
        pageSize: this.pageSize,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.courseBox {
  position: relative;
  box-sizing: border-box;

  .checkStudentStatus {
    width: 100%;
    height: 100%;
    position: absolute;
    z-index: 9;
    top: 0;
    background-color: #f3f2f7;
    padding: 20px 0 0 0;
    box-sizing: border-box;
  }
}

.courseBoxTopSearch {
  ::v-deep .el-input__inner {
    height: 36px;
    line-height: 36px;
  }
}

.courseScheduling {
  margin-left: 6px;
  color: #4b93d5;
  cursor: pointer;
}

.action {
  display: flex;
  align-items: center;
  justify-content: center;

  .copy {
    margin-left: 6px;
    color:#1990FF;
    cursor: pointer;
  }
}

::v-deep .el-icon-date {
  line-height: 36px;
}

.dialog {
  .block {
    width: 280px;
    height: 30px;
    border: solid 1px #dcdfe6;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    background-color: #fff;

    ::v-deep .el-input__inner {
      width: 240px;
      height: 28px;
      border: none;
    }

    ::v-deep .el-icon-arrow-down {
      color: #c2c2c2;
      padding: 0 10px 0 0;
    }

    ::v-deep .el-icon-arrow-up {
      color: #c2c2c2;
      padding: 0 10px 0 0;
    }

    ::v-deep .el-date-picker.has-sidebar {
      left: 460px !important;
      background-color: #4895db;
    }
  }

  ::v-deep .el-dialog {
    max-width: 750px;
    min-width: 500px;
    border-radius: 10px;
    background-color: #f9f9f9;
  }

  ::v-deep .el-dialog__header {
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    background-color: #4895db;
    padding: 0;
    border-radius: 10px 10px 0 0;

    span {
      font-size: 16px;
      color: #fff;
    }
  }

  ::v-deep .el-dialog__headerbtn {
    top: 15px;
  }

  ::v-deep .el-dialog__headerbtn .el-dialog__close {
    color: #fff;
    font-size: 18px;
  }

  ::v-deep .el-dialog--center .el-dialog__body {
    text-align: initial;
    display: flex;
    justify-content: center;
  }

  ::v-deep .el-input__inner {
    height: 30px;
    line-height: 30px;
  }

  ::v-deep .el-form-item__content {
    width: 300px;
  }

  ::v-deep .el-form-item {
    margin-bottom: 10px;
  }

  ::v-deep .el-dialog__footer {
    padding: 10px 20px 50px;
  }

  ::v-deep .el-button--default {
    width: 130px;
    border-radius: 20px;
    background-color: #fff;
    color: #4b95d6;
    border: solid 1px #4b95d6;
  }

  ::v-deep .el-button + .el-button {
    width: 130px;
    border-radius: 20px;
    margin-left: 50px;
    background-color: #4895db;
    border-color: #4895db;
  }
}

.dialog1 {
  ::v-deep .el-dialog {
    min-width: 1100px;
    border-radius: 10px;
    background-color: #f9f9f9;
  }

  ::v-deep .el-dialog__header {
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    background-color: #4895db;
    padding: 0;
    border-radius: 10px 10px 0 0;

    span {
      font-size: 16px;
      color: #fff;
    }
  }

  ::v-deep .el-dialog__headerbtn {
    top: 15px;
  }

  ::v-deep .el-dialog__headerbtn .el-dialog__close {
    color: #fff;
    font-size: 18px;
  }
}

.dialogBox {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  .mian {
    margin: 30px 0;

    .thd {
      display: flex;

      .thd_tr {
        .thd_th {
          width: 100px;
          height: 34px;
          display: flex;
          align-items: center;
          justify-content: center;
        }
      }
    }

    .tbd {
      display: flex;
      flex-direction: column;

      .el-input__inner {
        border: none;
        height: 32px;
      }

      ::v-deep .el-date-editor,
      ::v-deep .el-range__close-icon,
      ::v-deep .el-date-editor,
      ::v-deep .el-range-separator {
        line-height: 27px;
      }

      .tbd_tr {
        display: flex;

        .tbd_td {
          width: 100px;
          height: 34px;
          display: flex;
          align-items: center;
          justify-content: center;

          input {
            width: 100%;
            height: 100%;
            background-color: transparent;
            border: none;
            outline: none;
            text-align: center;
          }
        }

        .green {
          background-color: #a2ef4d;
          color: #fff;
          font-size: 12px;
        }

        .blue {
          background-color: #4095e5;
          color: #fff;
          font-size: 12px;
        }

        .yellow {
          background-color: #fcca00;
          color: #fff;
          font-size: 12px;
        }

        .red {
          background-color: #e01e0d;
          color: #fff;
          font-size: 12px;
        }

        .disabled,
        .gray {
          background-color: #9a9a9a;
          color: #9a9a9a;
          font-size: 12px;
        }
      }
    }
  }

  .dialog-footer {
    text-align: center;
  }
}

.colorBox {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 999;
  background-color: #fff;
  padding: 20px;
  border-radius: 5px;
  border: solid 1px #c2c2c2;
  display: flex;
  flex-direction: column;

  h4 {
    padding: 0 0 10px 0;
  }

  .colorBoxTop {
    display: flex;

    .colorBoxColor {
      .colorBoxUl {
        .colorBoxLi {
          width: 120px;
          display: flex;
          margin: 10px 0;
          cursor: pointer;

          i {
            width: 50px;
            height: 20px;
            margin-right: 10px;
          }

          span {
            font-size: 12px;
            min-width: 50px;
          }

          .yes,
          .none {
            display: none;
          }

          .block {
            display: block;
          }

          .white {
            background-color: #fff;
            border: solid 1px #9a9a9a;
          }

          .green {
            background-color: #a2ef4d;
          }

          .blue {
            background-color: #4095e5;
          }

          .yellow {
            background-color: #fcca00;
          }

          .red {
            background-color: #e01e0d;
          }

          .disabled,
          .gray {
            background-color: #9a9a9a;
          }
        }
      }
    }

    .colorBoxSelect {
      margin-left: 15px;

      .selectTeacher {
        margin-top: 20px;
      }
    }
  }

  .colorBoxBtn {
    margin-top: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    .el-button {
      width: 60px;
      height: 30px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}
</style>